package com.zkadmin.auditor;

import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.AuditorAware;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.zkadmin.service.SysUserService;

public class SysUserAuditorAware implements AuditorAware<Long> {
	@Autowired
	private SysUserService sysUserService;

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public Long getCurrentAuditor() {
		String principal = (String) SecurityUtils.getSubject().getPrincipal();
		return (principal != null) ? sysUserService.findByUsername(principal).getId() : null;
	}

}
